-
-
Notifications
You must be signed in to change notification settings - Fork 102
[4.2] Prevent context switching during id generation #2793
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
yrodiere
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @DavideD @tsegismont!
...rnate-reactive-core/src/main/java/org/hibernate/reactive/common/InternalStateAssertions.java
Outdated
Show resolved
Hide resolved
hibernate-reactive-core/src/main/java/org/hibernate/reactive/pool/impl/SqlClientPool.java
Outdated
Show resolved
Hide resolved
hibernate-reactive-core/src/main/java/org/hibernate/reactive/pool/impl/SqlClientPool.java
Show resolved
Hide resolved
hibernate-reactive-core/src/main/java/org/hibernate/reactive/pool/impl/SqlClientPool.java
Outdated
Show resolved
Hide resolved
hibernate-reactive-core/src/main/java/org/hibernate/reactive/pool/impl/SqlClientPool.java
Show resolved
Hide resolved
...-core/src/test/java/org/hibernate/reactive/MultithreadedInsertionWithLazyConnectionTest.java
Outdated
Show resolved
Hide resolved
...-reactive-core/src/main/java/org/hibernate/reactive/id/impl/BlockingIdentifierGenerator.java
Outdated
Show resolved
Hide resolved
e4fdfd4 to
9dce31a
Compare
For now we use it only when the connection is used
9dce31a to
5c245f9
Compare
This commit: * Stop connection leaks in BlockingIdentifierGenerator * Assert that the connection is used in the expected context
5c245f9 to
6b31752
Compare
|
I should have addressed all the comments. If CI doens't fail, I'm going to merge this so that I can start the release. Thanks a lot! |
37a5dda to
f7438b9
Compare
yrodiere
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @DavideD , LGTM!
| if ( connectionFuture.isDone() ) { | ||
| // connection exists, we can let callers use the delegate and forget about the proxy. | ||
| return connectionFuture.getNow( null ).withBatchSize( batchSize ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note the pattern if ( ... .isDone() ) { get() } should be avoided in general, because it's sensitive to TOCTOU. That's why I suggested var value = getNow(null); if ( value != null) .
Though in this case... I think the worst that could happen is a missed opportunity, so it's probably fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What I'm afraid of using getNow(null) in this case, it's that we will return null a bit too soon.
In this specific case, when .isDone() returns true, we should know for a fact that there's a result that we can return.
When it returns false, it's possible that by the time we call .getNow(null), the result is not null and we have created a ProxyConnection even if we didn't need to, but my guess is that this use case won't happen often.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Though in this case... I think the worst that could happen is a missed opportunity, so it's probably fine.
I didn't notice this line. Yes, that's what I was thinking.
The initial solution could have potentially caused a NullPointerException instead.
| } | ||
| else { | ||
| connection = connection.withBatchSize( batchSize ); | ||
| return new ProxyConnection( () -> opened |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So the opened check here is supposed to handle a case where someone does something like this?
<trigger connection request>
connection = connection.withBatchSize(...); // Connection not yet initialized somehow?
connection.doSomething();
That seems odd... did you do this because you noticed it actually happening?
In any case, +1 to be on the safe side.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's to be on the safe side.
Looking at the code, it seems to me there's a small window between setting opened to true and completing completableFuture with the connection. So, if opened it's true and completableFuture is not done, .getNow(null) will return null (and cause a NullPointerException), even if the connection is getting opened.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a bit late, I think I will sleep over it and merge it tomorrow morning if there are no other comments.
After that I will start the release.
Thanks
hibernate-reactive-core/src/main/java/org/hibernate/reactive/pool/impl/SqlClientPool.java
Outdated
Show resolved
Hide resolved
Now we test with and without transactions. And the test will throw an exception if context and connections aren't handled correctly.
f7438b9 to
01ebf2c
Compare
Fix #2768
Follows #2690 and it's a refactoring of @tsegismont suggestion.